<?php echo $this->Html->script('jquery-1.4.2.min.js'); ?>
<?php echo $this->Html->script('jquery-ui-1.8.4.custom.min.js'); ?>
<?php echo $this->Html->css('start/jquery-ui-1.8.4.custom.css'); ?>

	<h2 align = "center">Add Tweet</h2>
<head>

	<script type="text/javascript">
		function displayResult()
		{
		
			var phpLogin = document.getElementById("TweetText").value ;
			var num = 140 - phpLogin.length;
			var link = phpLogin.search("http");
			var link2 = phpLogin.search("www.");
			document.getElementById("Number").innerHTML = num;
			document.getElementById("Number").style.color = "#268613";
			if(num == 140){
				document.getElementById("Number").style.color = "#E41212";
			}
			if(num < 0){
				document.getElementById("TweetButton").disabled = true;
				document.getElementById("Number").style.color = "#E41212";
			}
			else{
					document.getElementById("TweetButton").disabled = true;
					for(var i = 0;i < phpLogin.length;i++){
						if(phpLogin.charAt(i)!=" "){
							document.getElementById("TweetButton").disabled = false;
							break;
						
					}
				
				}
			}
			if(link > -1 || link2 > -1){
				document.getElementById("TweetButton").disabled = false;
				document.getElementById("Number").style.color = "#DAB200";
			}
		
		}


		function SetEdit(Date,Text,Name,ID){
			document.getElementById("Editname").value = Name;
			document.getElementById("Edit").value = ID;
			document.getElementById("TweetText").value = Text;
			document.getElementById("drop").value = 0;
			var edit = "" + Date;
			var datetime = edit.split(" ");
			var date = datetime[0].split("-");
			document.getElementById("datepicker").value = date[1]+"/"+date[2]+"/"+date[0];
			var time = datetime[1].split(":");
			document.getElementById("hours").value = parseInt(time[0]);
			document.getElementById("minutes").value = parseInt(time[1]);
			$('#CancelEdit').show(1000);
			displayResult();
			Datetime();
			
		}


		function Cancel(){
			document.getElementById("Editname").value = '';
			document.getElementById("Edit").value = '';
			document.getElementById("TweetText").value = '';
			document.getElementById("datepicker").value = '';
			document.getElementById("hours").value = '';
			document.getElementById("minutes").value = '';			
			displayResult();
			$('#CancelEdit').hide(3000);
		}
		
		function Datetime(){
				
		if(document.getElementById("drop").value == 0){
		$('#datetime').fadeIn(4000);
		}
		else{
		$('#datetime').fadeOut(2000);
		}
		}
		
		$(window).load(function () {
			$('#CancelEdit').hide();
			document.getElementById("drop").remove("");
			displayResult();		});

		
		$(function(){$(
			 '#datepicker').datepicker();
	    });
		
	</script>
</head>
<br />
<style type="text/css">
	.tweetbutton:enabled {
		-moz-box-shadow:inset 0px 1px 0px 0px #ffffff;
		-webkit-box-shadow:inset 0px 1px 0px 0px #ffffff;
		box-shadow:inset 0px 1px 0px 0px #ffffff;
		background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, black), color-stop(1, #3669c2) );
		background:-moz-linear-gradient( center top, black 5%, grey 100% );
		filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#5ac5fa', endColorstr='#3669c2');
		background-color:black;
		-moz-border-radius:6px;
		-webkit-border-radius:6px;
		border-radius:6px;
		border:1px solid #4a569e;
		display:inline-block;
		color:#ffffff;
		font-family:arial;
		font-size:15px;
		font-weight:bold;
		float: right;
		padding:6px 16px;
		text-decoration:none;
	}.tweetbutton:disabled{
		-moz-box-shadow:inset 0px 1px 0px 0px #ffffff;
		-webkit-box-shadow:inset 0px 1px 0px 0px #ffffff;
		box-shadow:inset 0px 1px 0px 0px #ffffff;
		background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #f0f0f0), color-stop(1, #f0f0f0) );
		background:-moz-linear-gradient( center top, #f0f0f0 5%, #f0f0f0 100% );
		filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#f0f0f0', endColorstr='#f0f0f0');
		background-color:#000000;
		-moz-border-radius:6px;
		-webkit-border-radius:6px;
		border-radius:6px;
		border:1px solid #4a569e;
		display:inline-block;
		color:#b8b8b8;
		font-family:arial;
		font-size:15px;
		font-weight:bold;
		float: right;
		padding:6px 16px;
		text-decoration:none;
	}.tweetbutton:hover:enabled {
		background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, black), color-stop(1, #3669c2) );
		background:-moz-linear-gradient( center top, grey 5%, black 100% );
		filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#3669c2', endColorstr='#5ac5fa');
		background-color:black;
	}.tweetbutton:active:enabled {
		position:relative;
		bottom:1px;
	}.tweetbox{
		resize: vertical;
		font-size: 12px;
		height: 60px;
		border-radius:6px;
		border:3px solid #b8b8b8;
		width:785px;
		float:left;
	}.number:disabled{
		-moz-box-shadow:inset 0px 1px 0px 0px #ffffff;
		-webkit-box-shadow:inset 0px 1px 0px 0px #ffffff;
		box-shadow:inset 0px 1px 0px 0px #ffffff;
		background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #f0f0f0), color-stop(1, #f0f0f0) );
		background:-moz-linear-gradient( center top, #f0f0f0 5%, #f0f0f0 100% );
		filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#f0f0f0', endColorstr='#f0f0f0');
		background-color:#000000;
		-moz-border-radius:6px;
		-webkit-border-radius:6px;
		border-radius:6px;
		border:1px solid #4a569e;
		display:inline-block;
		color:#E41212;
		font-family:arial;
		font-size:15px;
		font-weight:bold;
		float: left;
		padding:6px 24px;
		text-decoration:none;
	}.time{
        resize: vertical;
        font-size: 14px;
        width: 55px;
		height: 33px;
        border-radius:15px;
        border:3px solid #b8b8b8;
		float:center;
    }.options{
		color:#E41212;
        font-size: 15px;
        border-radius:6px;
        border:3px solid #b8b8b8;
		float:right;
    }.box{
		width: 800px;	
	}.small{
		height: 22px;	
	}.mode{
        font-size: 16px;
        width: 350px;
		height: 33px;
        border-radius:11px;
        border:3px solid #b8b8b8;
	}
</style>
<div class = "box">
<?php
echo $this->Form->create();
echo $this->Form->select('options', array("Choose Date and Time","Set to Current Time","Add according to buffer time slots"),array('onchange'=>'Datetime()','class'=>'mode','value'=>'0','disabled'=>'false','id'=>'drop'));
echo $this->Form->button('X', array('id' => 'CancelEdit', 'class' => 'tweetbutton', 'type' => 'button', "onclick" => "Cancel()"));
echo $this->Form->textarea('Text', array("cols" => 5, "id" => "TweetText", "placeholder" => "Compose new Tweet...", "class" => "tweetbox", "onkeydown" => "displayResult('" . '' . "')", "onkeyup" => "displayResult()", "onselect" => "displayResult()", "onchange" => "displayResult()"));
echo $this->Form->input('Edit', array('id' => 'Edit', 'type' => 'hidden'));
echo $this->Form->input('Editname', array('id' => 'Editname', 'type' => 'hidden'));
?>
<br/>
<br/>
<br/>
<br/>
<br/>
<?php
echo $this->Form->button('Tweet', array('id' => 'TweetButton', 'disabled' => 'disabled','type' => 'submit' , 'class' => 'tweetbutton'));
echo $this->Form->button('140', array('id' => 'Number', 'class' => 'number', 'value' => '140', 'disabled' => 'disabled'));
?>
<br/>
<div align = "center" id = "datetime">
<?php
echo $this->Form->input('Date', array('type' => 'text','id' => 'datepicker', 'style' => 'width:50px'));
echo "  Time  ";
echo $this->Form->select('hours',array(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23), array('id'=>'hours','class'=>'time'));
echo " : ";
echo $this->Form->select('minutes', array(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59),array('id'=>'minutes','class'=>'time'));
?>
</div>
</div>
 
	<html xmlns="http://www.w3.org/1999/xhtml">
<head>
 
  <script>

	function setFilter(){
	document.getElementById("filter").value = 1;
	}
    $(function(){$(
       '#datepicker1').datepicker();
      });
  $(document).ready(function() {
    $("button").button();
  });

  $(document).ready(function() {
    $("#change").popover(options);
  });

  </script>
  
  
  

</head>

<body>
	<?php if($results[1] == array()) { ?>
        <h2 align="center"><b><i>Looks like your buffer is empty! Go ahead fill it up !</i></b></h2>

        <?php } else { ?>
    <table>
        
        
        <?php
        	$currentDate= $results[1][0]['FutureTweet']['release_date'];
        	//debug($results);
        	//debug(CakeTime::isToday($currentDate, $timezone = NULL));
        	$currentDay = $results[1][0]['FutureTweet']['day'];
        	if(CakeTime::isToday($currentDate, $timezone = NULL)){?>
        		<h2>Today</h2>
        	<?php }
        	else if(CakeTime::isTomorrow($currentDate, $timezone = NULL)){ ?>
        		<h2>Tomorrow</h2>
        	<?php }
        	else { ?>
        		<h2><?php echo $currentDay ?></h2>
        	<?php }

        	foreach($results[1] as $field): ?>
        	<?php 
        		if(CakeTime::isTomorrow($field['FutureTweet']['release_date'], $timezone = NULL)&& $field['FutureTweet']['day'] != $currentDay){ ?>
        			<tr><th><h2>Tomorrow</h2></th></tr>
        			
        		<?php 
        		$currentDay = $field['FutureTweet']['day'];
        		}
        		else if($field['FutureTweet']['day'] != $currentDay){
        		$currentDay = $field['FutureTweet']['day']; ?>
        		<tr><th><h2><?php echo $currentDay; ?> </h2></th></tr>
        		<?php } ?>
        	
            <tr style="background-color:#FFFFFF">
            	 
              <th> <?php echo $field['FutureTweet']['hour'] ?></th>
              <th> <?php echo $field['FutureTweet']['tweet_text'] ?></th>
              <th> <?php echo "By: ".$field['FutureTweet']['name'] ?></th>
              <th> <?php echo $field['FutureTweet']['status']; ?></th>
			  <?php if($field['FutureTweet']['user_email'] == $email){ ?>
			  <th width = 20px> <?php echo $this->Html->link('Edit', "javascript:SetEdit('".$field['FutureTweet']['release_date']."','".$field['FutureTweet']['tweet_text']."','".$field['FutureTweet']['user_email']."','".$field['FutureTweet']['id']."')");
			  ?></th>
			  <th width = 20px> <?php echo $this->Html->link('Delete', array('action'=>'deleteTweet' , $field['FutureTweet']['id']),array('confirm' => 'Are you sure?'));
			  }?>
              
			  <?php if($results[0] == 'moderator' && $field ['FutureTweet']['status'] == 'pending') { ?>
              <th width = 20px><?php echo $this->Html->link('Approve', array('action'=>'approvePost' , $field['FutureTweet']['id'])); ?></th>
              <th width = 20px><?php echo $this->Html->link('Decline', array('action'=>'declinePost' , $field['FutureTweet']['id'])); ?></th>
			  <?php } ?>
			  </th>

            </tr>
       <!-- <td>
            <button type="button" onclick="displayDate()">Edit</button>
            <button type="button"   onclick="displayDate()">Delete</button>
        </td>-->

        
        <?php endforeach;?>
    </table>

    <?php } ?>
 

    
</body>
</html>